import gtk
import gobject
import gconf
import unittest

c = gconf.client_get_default()

def get_string(key):
    assert isinstance(key, str)
    return c.get_string(key)

class CheckButton(gtk.CheckButton):
    def toggled(self, *w):
        value = self.get_active()
        c.set_bool(self.key, value)
    def __init__(self, text, key):
        assert isinstance(text, (str,unicode))
        assert isinstance(key, str)
        gtk.CheckButton.__init__(self)
        self.set_label(text)
        self.key = key
        self.set_active(c.get_bool(key))
        self.connect('toggled', self.toggled)

class _test(unittest.TestCase):
    def test_checkbutton(self):
        import ui
        b = CheckButton('visible', '/apps/nautilus/desktop/computer_icon_visible')
        def callback(w):
            print w.get_active()
        b.connect('i_toggled', callback)
        window = ui.window(b)
        window.set_size_request(400, 200)
        gtk.main()
